package cn.sun.org.service.impl;

import cn.sun.basic.service.IBaseService;
import cn.sun.basic.service.impl.BaseServiceImpl;
import cn.sun.basic.util.PageBean;
import cn.sun.org.domain.Department;
import cn.sun.org.mapper.DepartmentMapper;
import cn.sun.org.query.DepartmentQuery;
import cn.sun.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl extends BaseServiceImpl<Department,DepartmentQuery> implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void save(Department department) {
        departmentMapper.save(department);
        this.update(department);
    }

    @Override
    public void update(Department department) {
        String dirPath =null;
        String pdirpath=null;
        if (department.getParent()!=null){
            //根据父级部门的id查询父级部门的信息
            Department department1 = departmentMapper.findById(department.getParent().getId());

            pdirpath = department1.getDirPath();

        }
        dirPath=pdirpath+"/"+department.getId();
        department.setDirPath(dirPath);
        departmentMapper.update(department);
    }

    @Override
    public void drukdel(List<Long> ids) {
        departmentMapper.drukdel(ids);
    }

    @Override
    public List<Department> getDeptTree() {
        return departmentMapper.getDeptTree();
    }
}
